package com.umeox.iqibla.azkar.db

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

/**
 * Created by Rambo 2024/3/28/0028
 * Describe:
 */
@Dao
interface AzkarDao {

    @Query("SELECT * FROM azkar_record WHERE todayMillis >= :nDaysMillis AND todayMillis <= :todayMillis ORDER BY todayMillis DESC")
    fun loadLast30DayList(nDaysMillis: Int,todayMillis: Int):MutableList<Azkar>?

    @Query("SELECT * FROM azkar_record WHERE isUpload = 0 AND count > 0")
    fun loadNoUploadList():MutableList<Azkar>?

    @Query("SELECT * FROM azkar_record WHERE todayMillis = :todayMillis")
    fun queryByTodayMillis(todayMillis: Int):Azkar?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun save(azkar: Azkar): Long

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun save(azkar: List<Azkar>)

    @Query("SELECT SUM(count) FROM azkar_record WHERE todayMillis >= :nDaysMillis AND todayMillis <= :todayMillis")
    fun queryLast30DayListSumCount(nDaysMillis: Int,todayMillis: Int) : Int

    @Query("SELECT count FROM azkar_record WHERE todayMillis >= :todayMillis")
    fun queryTodayAzkarCount(todayMillis: Int):Int

    @Query("SELECT todayMillis FROM azkar_record  ORDER BY todayMillis DESC LIMIT 1")
    fun queryLatestRecordTodayMillis():Int

    @Query("SELECT count FROM azkar_record  ORDER BY todayMillis DESC LIMIT 1")
    fun queryLatestRecordCount():Int

    @Query("DELETE FROM azkar_record")
    fun deleteAll()
}